
// 基类组件,通过 Vue({extend: BaseListComponent })引用
export default {
    created() {
        console.log('base list created')
        console.log('loadListMethod : ' + this.loadListMethod)
        if(this.loadListMethod!=null && this.loadListMethod!=undefined&&this.loadListMethod!=''){
            this.loadList()
        }
    },
    mounted() {
        
    },
    data() {
        // 公共数据,没有return对象返回null，在合并的时候导致异常报错
        return {
            loadListMethod: 'getExampleList',
            baseListData: {

            },
            dataList: [
                // {
                //   title: "实体店专业高价回收",
                //   city: "哥伦比亚",
                //   price: "面议",
                //   date: "03-07",
                //   img: "",
                // },
            ],
            scroll: {
                height: 0,
                disabled: false, // 下拉刷新禁用
                distance: 0, // 下拉刷新触发距离
                noMore: false, // 没有更多数据
                loading: false, // 加载中
                delay: 500, // 延迟
                t: null,
            },
            page: {
                pageIndex: 1, // 分页索引
                pageSize: 10, // 分页大小
                // 过滤参数
                filters: {
                    city: "哥伦比亚",
                    county: "WEIU",
                    type: "",
                    price: "",
                    keyword: "文件覅我",
                },
            },
        }
    },
    methods: {
        // 公共组件方法
        loadList() {
            if (this.scroll.disabled || this.scroll.noMore) {
                console.log('scroll.disabled:' + this.scroll.disabled + ', scroll.noMore:' + this.scroll.noMore)
                return
            }
            console.log('loadList,pageIndex:' + this.page.pageIndex)
            let methods = this.$options.methods
            this.scroll.loading = true
            this.scroll.disabled = true
            setTimeout(() => {
                methods[this.loadListMethod](this.page)
                    .then((res) => {
                        let { code, msg, data } = res
                        let { rows, count } = data
                        console.log(res)
                        if (code == 200) {
                            if (rows.length == 0) {
                                this.scroll.disabled = true
                                this.scroll.noMore = true
                                console.log('no more')
                            } else {
                                this.dataList = this.dataList.concat(rows)
                                this.page.pageIndex += 1
                            }
                        } else {
                            // msg
                        }
                    })
                    .catch((err) => { })
                    .finally(() => {
                        this.scroll.loading = false
                        setTimeout(() => {
                            this.scroll.disabled = false
                        }, 100)
                    })
            }, 1000)
        }
    },
}